package org.sn.jdish.interview.thoughtworks.purchase;

/**
 * 商品工具
 */
public class MerchandiseUtil {

	/**
	 * 转换为newMerchandise实体
	 * 
	 * @param newMerchandises
	 * @return
	 */
	public static Merchandise convet2NewMerchandise(String[] newMerchandises) {
		Merchandise newMerchandise = new Merchandise();
		newMerchandise.setNewTime(newMerchandises[0]);
		newMerchandise.setBarCode(newMerchandises[2]);
		newMerchandise.setName(newMerchandises[3]);
		newMerchandise.setPrice(Double.parseDouble(newMerchandises[4]));
		return newMerchandise;
	}

	/**
	 * 转换为purchaseMerchandise实体
	 * 
	 * @param purchaseMerchandises
	 * @return
	 */
	public static Merchandise convet2PurchaseMerchandise(String[] purchaseMerchandises) {
		Merchandise purchaseMerchandise = new Merchandise();
		purchaseMerchandise.setPurchaseTime(purchaseMerchandises[0]);
		purchaseMerchandise.setBarCode(purchaseMerchandises[2]);
		purchaseMerchandise.setPurchaseNum(Integer.parseInt(purchaseMerchandises[3]));
		purchaseMerchandise.setPurchasePrice(Double.parseDouble(purchaseMerchandises[4]));
		return purchaseMerchandise;
	}

	/**
	 * 转换为salesMerchandise实体
	 * 
	 * @param salesMerchandises
	 * @return
	 */
	public static Merchandise convet2SalesMerchandise(String[] salesMerchandises) {
		Merchandise salesMerchandise = new Merchandise();
		salesMerchandise.setSalesTime(salesMerchandises[0]);
		salesMerchandise.setBarCode(salesMerchandises[2]);
		salesMerchandise.setSalesNum(Integer.parseInt(salesMerchandises[3]));
		return salesMerchandise;
	}

	/**
	 * 报表内容处理
	 * 
	 * @param merchandiseName
	 * @param inventoryQuantity
	 * @param inventoryAmount
	 * @param salesQuantity
	 * @param salesAmount
	 * @param profit
	 * @return
	 * @throws Exception
	 */
	public static String output(String merchandiseName, int inventoryQuantity, double inventoryAmount,
			int salesQuantity, double salesAmount, double profit) throws Exception {
		StringBuilder output = new StringBuilder();
		output.append("Merchandise: ");
		output.append(merchandiseName);
		output.append(", ");
		output.append("Inventory Quantity: ");
		output.append(inventoryQuantity);
		output.append(", ");
		output.append("Inventory Amount: ");
		output.append(inventoryAmount);
		output.append(", ");
		output.append("Sales Quantity: ");
		output.append(salesQuantity);
		output.append(", ");
		output.append("Sales Amount: ");
		output.append(salesAmount);
		output.append(", ");
		output.append("Profit: ");
		output.append(profit);
		output.append("\n");
		return output.toString();
	}

}
